import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate'

Vue.use(Vuex)

export default new Vuex.Store({
  plugins: [createPersistedState({
    storage: window.sessionStorage
  })],
  state: {
    token: '',
    account: '',
    questionList: [],
    routes: [],
    role: '',
    permission: ''
  },
  mutations: {
    SET_TOKEN: (state, token) => {
      state.token = token
    },
    SET_ACCOUNT: (state, account) => {
      state.account = account
    },
    SET_QUESTION_LIST: (state, questionList) => {
      state.questionList = questionList
    },
    SET_ROUTES: (state, routes) => {
      state.routes = routes
    },
    SET_ROLE: (state, role) => {
      state.role = role
    },
    SET_PERMISSION: (state, permission) => {
      state.permission = permission
    }
  },
  getters: {
    GET_TOKEN: state => {
      return state.token
    },
    GET_ACCOUNT: state => {
      return state.account
    },
    GET_QUESTION_LIST: state => {
      return state.questionList
    },
    GET_ROUTES: state => {
      return state.routes
    },
    GET_ROLE: state => {
      return state.role
    },
    GET_PERMISSION: state => {
      return state.permission
    }
  }
})
